package sk.ogame.realm.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sk.ogame.realm.service.SailService;

import java.util.Objects;

/**
 * @author 支绍昆
 *         2023/3/7
 *         工具类
 **/
@Controller
@RequestMapping("/util")
public class UtilController {

    private static int number = 0;

    @GetMapping
    public String util(Model model) {
        return "util";
    }

    @ResponseBody
    @GetMapping("/carry/num")
    public String carry(Integer m, Integer k, Integer shipId) {
        if (Objects.isNull(k)) {
            k = 0;
        }
        if (Objects.isNull(m)) {
            m = 0;
        }
        return String.valueOf(SailService.countShipNumber(shipId, m * 1000_000 + k * 1000));
    }

    @ResponseBody
    @GetMapping("/attack/num")
    public String attack(Integer m, Integer c, Integer d, Integer shipId) {
        if (Objects.isNull(m)) {
            m = 0;
        }
        if (Objects.isNull(c)) {
            c = 0;
        }
        if (Objects.isNull(d)) {
            d = 0;
        }
        return String.valueOf(SailService.attackShipNumber(shipId, m + c + d));
    }

}
